package cn.vser.server.demo;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;

import cn.vser.server.VserApi;

@Service
public class WebApplication implements ApplicationListener<ApplicationEvent>, ApplicationContextAware {

    @Value("${vser.sdk.key}")
    private String sdkKey;
    @Value("${vser.sdk.secret}")
    private String sdkSecret;
    @Value("${vser.api.server}")
    private String server;
    
    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof ContextRefreshedEvent) {
            initialization();
        }
        if (event instanceof ContextClosedEvent) {
            
		}
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {
        VserApi.initialize(sdkKey, sdkSecret, server);
    }

    public void initialization() {
    	
    }
}
